# -*- coding: utf-8 -*-
'''
author:Cooper
date:2012.5.1
交易API:
taobao.topats.trades.fullinfo.get
tabao.trade.fullinfo.get
taobao.trade.get
taobao.trades.sold.get
taobao.trades.sold.increment.get
'''

from TopAPI.lib import *
import json

trade_fields='tid,num,num_iid,status,title,\
type,price,seller_cod_fee,discount_fee,point_fee,\
has_post_fee,total_fee,is_lgtype,is_brand_sale,is_force_wlb,\
created,pay_time,modified,end_time,buyer_message,\
alipay_id,alipay_no,alipay_url,buyer_memo,buyer_flag,\
seller_memo,seller_flag,invoice_name,buyer_nick,buyer_area,\
buyer_email,has_yfx,yfx_fee,yfx_id,has_buyer_message,\
shipping_type,buyer_cod_fee,express_agency_fee,adjust_fee,buyer_obtain_point_fee,\
cod_fee,trade_from,alipay_warn_msg,cod_status,can_rate,\
service_orders,commission_fee,trade_memo,seller_nick,iid,\
pic_path,payment,snapshot_url,snapshot,seller_rate,\
buyer_rate,real_point_fee,post_fee,buyer_alipay_no,receiver_name,\
receiver_state,receiver_city,receiver_district,receiver_address,receiver_zip,\
receiver_mobile,receiver_phone,consign_time,seller_alipay_no,seller_mobile,\
seller_phone,seller_name,seller_email,available_confirm_fee,received_payment,\
timeout_action_time,is_3D,orders,promotion,promotion_details'

class trade_topats():
	api='taobao.topats.trades.fullinfo.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json',tids=''):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']='download_url,check_code,schedule,task_id,status,\
		subtasks,method,created'
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'task')
	pass

class trade_detailed():
	api='taobao.trade.fullinfo.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json',tid=''):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=trade_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'trade')
	pass

class trade():
	api='taobao.trade.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json',tid=''):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=trade_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'trade')
	pass

class trades_sold():
	api='taobao.trades.sold.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json',
		start_created=None,end_created=None,
		status=None,buyer_nick=None,
		type=None,ext_type=None,
		rate_statue=None,tag=None,
		page_no=None,page_size=None,
		use_has_next=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=trade_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'trades')
	pass

class trades_sold_incre():
	api='taobao.trades.sold.increment.get'
	def __init__(self):
		self.method=self.api
		self.setParams()
	def setParams(self,session,format='json',
		start_modified='',end_modified='',
		status=None,type=None,
		ext_type=None,tag=None,
		page_no=None,page_size=None,
		use_has_next=None):
		self.__dict__.update(locals())
	def getRes(self):
		d={k:v for k,v in self.__dict__.items() if k!='self' and v!=None}
		d['fields']=trade_fields
		url=getURL(d)
		return getRes(url)
	def parseItem(self):
		r=self.getRes()
		j=json.loads(r.content,r.encoding)
		return parseJsonField(j,'trade')
	pass

def main():
	pass

if __name__=='__main__':
	main()
	pass
